<?php
function clearCookies(){
    setcookie('username','',time()-3600);
    setcookie('islogin','',time()-3600);
}
if ($_GET){
if($_GET['action']=="login"){
    clearCookies();
    if($_POST['username']=="admin" && $_POST['password']==123456){
        setcookie('username',$_POST["username"],time()+60*60*24*7);
        setcookie('islogin',1,time()+60*60*24*7);
        header("Location:index.php");
    }else{
        die("用户名或密码错误");
    }

    }else if($_GET["action"]=="logout") {
    clearCookies();

}
}
?>
<html>
<head>
    <title>登陆</title>
    <meta charset="utf-8"/>
</head>
<body>
<form action="login.php?action=login" method="post">
    <table>
        <tr><td>用户名：</td><td><input type="text" name="username"></td></tr>
        <tr><td>密码： </td><td><input type="password" name="password"></td></tr>
        <tr><td><input type="submit" value="提交"></td><td><input type="reset" value="重置"></td></tr>
    </table>
</form>
</body>

</html>